#pragma once
#include "time.h"
#include <vector>
#include "eventhandler.h"
#include "AlarmEvent.h"
#include "Reactor.h"
#include "SOCK_Acceptor.h"

namespace Network 
{
	typedef struct AlarmEventItem_ {
		AlarmEvent event;
		time_t timestamp;

		AlarmEventItem_(AlarmEvent event_, time_t timestamp_) : event(event_), timestamp(timestamp_) {}

	} AlarmEventItem;

	//comparer
	struct AlarmEventItemPriorityComparer{
		inline bool operator()(const AlarmEventItem &a, const AlarmEventItem &b) {
			return a.event.priority < b.event.priority;
		}
	};
	
	class AlarmEventHandler : EventHandler
	{
	protected:
		SOCK_Acceptor* listener;
		std::vector<AlarmEventItem> alarms;
	public:
		AlarmEventHandler(const INET_Addr& ipAddress);
		~AlarmEventHandler() {  } 

		virtual void handle(unsigned char* data);
		virtual SOCK_Acceptor getHandle() { return *listener; };
		virtual EventType getType() { return ALARM_EVENT; }
	};
}
